Page({

  /**
   * 页面的初始数据
   */
  data: {
    types: [
      {
        name: '微信支付',
        img: "../../images/cart/weixin.png",
        id: 0
      },
      {
        name: '支付宝支付',
        img: "../../images/cart/zhifubao.png",
        id: 1
      }, {
        name: '钱包支付(余额0.00)',
        img: "../../images/cart/shouyi.png",
        id: 2
      },
      {
        name: '建设银行储蓄卡(6588)',
        img: "../../images/cart/jianhang.png",
        id: 3
      }
    ],
    typeId: 0, //支付类型的id
  },
  //选择店铺
  typeSelected: function (e) {
    var that = this;
    let id = e.currentTarget.dataset.id;
    that.setData({
      typeId: id
    })
    console.log(this.data.typeId);
    switch (this.data.typeId) {
      case 0:
        console.log("选择了微信支付")
        break;
      case 1:
        console.log("选择了支付宝支付")
        wx.requestPayment({
          data: {
            app_id: '800000040005',
            method: 'tp.trade.confirm',
            sign: '4e70a84d9080e74a1a00b715818b809b',
            sign_type: 'MD5',
            timestamp: '1534342228111',
            trade_no: '20180821162045321823181631558207',
            merchant_id: '1300000004',
            uid: '6287430262',
            total_amount: 12,
            pay_channel: 'ALIPAY_NO_SIGN',
            risk_info: '172.17.189.65',
            pay_type: 'ALIPAY_APP',
            params: JSON.stringify({
              // 如果是新版支付宝，url 示例：
              url: 'app_id=2018041302549907&biz_content=%7B%22body%22%3A%22novel%22%2C%22subject%22%3A%22%E6%B5%8B%E8%AF%95%E7%9A%84%E5%95%86%E5%93%81%22%2C%22out_trade_no%22%3A%22201808211756233909095950%22%2C%22timeout_express%22%3A%2230m%22%2C%22total_amount%22%3A%220.01%22%2C%22seller_id%22%3A%22jrtoutiaoyxgs%40bytedance.com%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&charset=utf-8&format=JSON&method=alipay.trade.app.pay&notify_url=https%3A%2F%2Ftp-pay-test.snssdk.com%2Fcallback%2Fali_pay&sign=ZfVkvu%2FSzBqFuqQMgr6MvsXomlr6BCuz7GYDnpsxd3SLVfCssV0q2cnxZyfjh%2FY%2Bk7PO1IeEl4rppQg%2FXgRuIqMXyKdhmigj4oPdQVJEkbSQEcCW4m8mwpXLNjlLH%2FHae3u3hjrMDVPuVXeIxjoq1NLPXy09GY5u1MX8E2lkn8xtmOxA2cXXRIrAa8gTplUoXWkSSkZMgvSTzQ9RjRmlKtK4nERdDWh5RBXLNDU%2FD2FfqIeZuLNZh%2BW8j4dYGtPDm9nWYRz0tLizJDm6E76aTM3qvLi0havCCrHgxZ5d8tVN7GNztA6olbGOiXubEGUq4yBqCojiALEEVpKqfQdZGQ%3D%3D&sign_type=RSA2&timestamp=2018-08-21+17%3A56%3A24&version=1.0'
            }),
          },
          success(res) {
            debugger
            console.log(res.errMsg);
          },
          fail(res) {
            debugger
            console.log(res.errMsg);
          }
        })
        wx.navigateTo({
          url:"../order-pay-success/order-pay-success"
        })
        break;
      case 2:
        console.log("选择了钱包支付")
        break;
      case 3:
        console.log("选择了银行卡支付")
        break;
      case "再次购买":
        break;
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function (options) {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  addIDCard: function () {
    wx.navigateTo({
      url: '../my-card/add-card/index' // 指定页面的url
    });
  }
})